#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=9e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn];
LL cnt=0;
struct Stone{
    LL l,w,h;
}stone[maxn];
bool cmp(Stone A,Stone B){
    if(A.l==B.l){
        if(A.w==B.w) return A.h>B.h;
        return A.w>B.w;
    }
    return A.l>B.l;
}
void add(LL a,LL b,LL c){
    stone[++cnt].l=a;
    stone[cnt].w=b;
    stone[cnt].h=c;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;n=read();
  for(LL i=1;i<=n;i++){
     LL l,r,h;l=read();r=read();h=read();
     add(max(r,h),min(r,h),l);
     add(max(l,h),min(l,h),r);
     add(max(l,r),min(l,r),h);
  }
  sort(stone+1,stone+1+cnt,cmp);
  for(LL i=1;i<=cnt;i++){
    dp[i]=stone[i].h;
  }
  /*
  for(LL i=1;i<=cnt;i++){
    cout<<stone[i].l<<" "<<stone[i].w<<" "<<stone[i].h<<'\n';
  }*/

  for(LL i=1;i<=cnt;i++){
    for(LL j=1;j<i;j++){
        if(stone[j].l>stone[i].l&&stone[j].w>stone[i].w){
            dp[i]=max(dp[i],dp[j]+stone[i].h);
        }
    }
  }
  LL ans=-1e18;
  /*
  for(LL i=1;i<=cnt;i++){
    cout<<dp[i]<<"\n";
  }*/
  for(LL i=1;i<=cnt;i++){
    ans=max(ans,dp[i]);
  }
  cout<<ans<<"\n";
return 0;
}
